import axios from 'axios'
import {Toast} from 'vant'

let loading = null;

axios.interceptors.request.use(config=>{

    if(window.location.hostname == 'localhost'){
        config.url = config.url;
    }
    config.url = '/api' + config.url;
    // console.log('config', config);

    loading = Toast.loading({
        mask: true,
        forbidClick: true,
        message: '正在加载'
    });

    return config;
}, error=>{
    console.error('加载超时');
    loading.clear();
    return Promise.reject(error);
});

axios.interceptors.response.use(({data = {}})=>{
    loading.clear();
    return data;
}, error=>{
    loading.clear();
    return Promise.reject(error);
});

export default axios